#ifndef TTY_H
#define TTY_H 

#include "dev.h"
#include "sem.h"

#define TTY_NR 8

#define TTY_IBUF_SIZE 512
#define TTY_OBUF_SIZE 512
#define TTY_OCRLF	(1 << 0)

typedef struct _tty_fifo_t {

    char* buf;
    int size;
    int read, write;
    int count;

} tty_fifo_t;

typedef struct _tty_t {

    char ibuf[TTY_IBUF_SIZE];
    tty_fifo_t ififo;
    char obuf[TTY_OBUF_SIZE];
    tty_fifo_t ofifo;
    sem_t osem;

    int console_index;
    int oflags;

} tty_t;


void tty_fifo_init(tty_fifo_t* fifo, char* buf, int size);

int tty_fifo_put(tty_fifo_t* fifo, char c);

int tty_fifo_get(tty_fifo_t* fifo, char* c);

int tty_open(device_t *dev);

int tty_read(device_t *dev, int addr, char* buf, int size);

int tty_write(device_t *dev, int addr, char* buf, int size);

int tty_control(device_t *dev, int cmd, int arg0, int arg1);

void tty_close(device_t *dev);

#endif /* ifndef TTY_H */
